
import 'package:flutter/material.dart';
import 'package:flutter_trip/base_view/base_appbar.dart';

const CITY_NAMES = [ '北京', '上海', '广州', '深圳', '杭州', '苏州', '成都', '武汉', '郑州', '洛阳', '厦门', '青岛', '拉萨' ];

class MyGrideView extends StatefulWidget {
  @override
  _MyGrideViewState createState() => _MyGrideViewState();
}

class _MyGrideViewState extends State<MyGrideView> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: getAppbarLeading('网格布局',ElevatedButton(onPressed: (){
        Navigator.pop(context);
      }, child: Icon(Icons.arrow_back)),
      ),

      body: GridView.count(crossAxisCount: 3,
      children: _buildList(),

      ),
    );
  }

  List<Widget>_buildList(){
    return CITY_NAMES.map((e) => _item(e)).toList();
  }

  Widget _item(String city){
    return Container(
      height: 80,
      margin: EdgeInsets.only(bottom: 5,left: 5),
      alignment: Alignment.center,
      decoration: BoxDecoration(color: Colors.teal),
      child: Text(city,
            style: TextStyle(color: Colors.white,
            fontSize: 20),
      ),
    );
  }
}
